package com.zzw.service;

import com.zzw.entity.SysUser;
import com.zzw.entity.SysUserRole;
import com.zzw.mapper.dao.SysUserMapper;
import com.zzw.mapper.dao.SysUserRoleMapper;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

@Service
@CacheConfig(cacheNames = "sysUserRoleService")
public class SysUserRoleService {

    private SysUserRoleMapper sysUserRoleMapper;

    @CachePut(key = "#p0.id", unless = "#result eq null")  //#p0表示第一个参数
    public SysUserRole insertSysUserRole(SysUserRole sysUserRole) {
        sysUserRoleMapper.insert(sysUserRole);
        return sysUserRole;
    }

    @CachePut(key = "#p0.id", unless = "#result eq null")  //#p0表示第一个参数
    public SysUserRole updateSysUserRole(SysUserRole sysUserRole) {
        sysUserRoleMapper.updateByPrimaryKey(sysUserRole);
        return sysUserRole;
    }

    @CacheEvict(key = "#p0.id")  //删除缓存名称为userCache,key等于指定的id对应的缓存
    public int deleteSysUserRole(SysUserRole sysUserRole) {
        return sysUserRoleMapper.delete(sysUserRole);
    }

    @Cacheable(key = "#p0.id", unless = "#result eq null")  //#p0表示第一个参数
    public SysUserRole selectSysUserRole(SysUserRole sysUserRole) {
        return sysUserRoleMapper.selectOne(sysUserRole);
    }

    @CacheEvict(allEntries = true)
    public int deleteAll() {
        return sysUserRoleMapper.delete(null);
    }

    @CacheEvict(allEntries = true)
    public int deleteByIds(String ids) {
        return sysUserRoleMapper.deleteByIds(ids);
    }
}
